﻿using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_DangKiThanhVien : System.Web.UI.UserControl
{
   
    protected void btnDangKi_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        XuLy xl = new XuLy();
        string query = "select TenDN from KhachHang where TenDN='" + txtTenDN.Text.Trim() + "'";
       
        dt = xl.Load(query);
        if (dt.Rows.Count > 0)
        {
            lbLoi.Visible = true;
            
            lbLoi.Text = "Tên đăng nhập này đã tồn tại";
            lbLoi.Visible = true;

            lbLoi.ForeColor = Color.Red;
            //txtTenDN.Focus = true;
            txtMatKhau.Text = "";
            txtNhapLaiMK.Text = "";
        }
        else
        {
            string gioiTinh = "";
            if (rbNu.Checked == true)
            {
                gioiTinh = "Nữ";
            }
            else
            {
                gioiTinh = "Nam";
            }
            string gioitinh = Convert.ToString(gioiTinh);
            int taikhoan = int.Parse(txtTaiKhoan.Text);
            string query1 = "insert into KhachHang values('" + txtTenDN.Text.Trim() + "',N'" + txtHoTen.Text.Trim() + "',N'" + txtEmail.Text.Trim() + "',N'" + txtMatKhau.Text.Trim() + "',N'" + txtDiaChi.Text.Trim() + "',N'" + txtSoDT.Text.Trim() + "',N'" + gioitinh + "',N'" + taikhoan+ "')";
            xl.XuLyDuLieu(query1);
            Response.Redirect("BaoLoi.aspx?mod=SignUp");// dang ki thanh cong 
            
        }
        
        /*XuLy xl = new XuLy();
       
            string gioiTinh="";
            if (rbNu.Checked==true)// 
            {
                gioiTinh="Nữ";
            }
            else
            {
                gioiTinh="Nam";
            }
            //double taikhoan = Convert.ToDouble(txtTaiKhoan.Text);
           //int taikhoan = Int32.Parse(txtTaiKhoan.Text);


            //string query = "insert into KhachHang values('" + txtTenDN.Text + "','" + txtHoTen.Text + "','" + txtEmail.Text + "','" + txtMatKhau.Text + "','" + txtDiaChi.Text + "','" + txtSoDT.Text + "','" +gioiTinh+"','"+ taikhoan+ "')";
           string query = "insert into KhachHang values('" + txtTenDN.Text + "',N'" + txtHoTen.Text + "',N'" + txtEmail.Text + "',N'" + txtMatKhau.Text + "',N'" + txtDiaChi.Text + "',N'" + txtSoDT.Text + "',N'" + gioiTinh + "',N'" + txtTaiKhoan.Text + "')";
            xl.XuLyDuLieu(query);
            Response.Redirect("BaoLoi.aspx?mod=SignUp");*/
         

        
    }
    protected void btnNhapLai_Click(object sender, EventArgs e)
    {
       
        txtHoTen.Text = "";
        txtTenDN.Text = "";
        txtMatKhau.Text = "";
        txtNhapLaiMK.Text = "";
        txtEmail.Text = "";
        txtDiaChi.Text = "";
        txtSoDT.Text = "";
        txtTaiKhoan.Text = "";
    }

    
    protected void Page_Load(object sender, EventArgs e)
    {
        lbLoi.Visible = false;
        txtHoTen.Text = "";
        txtTenDN.Text = "";
        txtMatKhau.Text = "";
        txtNhapLaiMK.Text = "";
        txtEmail.Text = "";
        txtDiaChi.Text = "";
        txtSoDT.Text = "";
        txtTaiKhoan.Text = "";
    }
}